/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package snippet.theory9;

import java.lang.reflect.*;
import java.util.logging.Level;
import java.util.logging.Logger;

class Student {

    public String name;

    public int age;

    void displayName() {

    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
    
}

/**
 *
 * @author hoang.pt
 */
public class ReflectionDemo {

    public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException {

        Student t = new Student("hoang.pt", 18);
        try {
            printClass(t);
        } catch (NoSuchFieldException ex) {
        }
    }

    public static void printClass(Object x) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {

        Class classes = x.getClass();
        System.out.println(classes.toString());

        String className = classes.getName();
        System.out.println(className);

        Field lengthField = classes.getField("name");
        System.out.println(lengthField);
        System.out.println(lengthField.get(x));

        Field[] c= classes.getFields();
        for (Field field : c) {
            System.out.println(field.getName());
        }
    }
}
